package com.rtos.model.memory;

import com.rtos.model.process.PCB;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import lombok.extern.java.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: biubiu0002
 * @Date: 2021-09-03 0:11
 * 系统区内存
 **/
@Log
public class SystemMemory {
    private volatile static ObservableList<PCB> PCB_AREA = FXCollections.observableArrayList();
//    public static MAT mat = MAT.getInstance();

    public static List<PCB> getPCBList(){
        return PCB_AREA;
    }

    public static ObservableList<PCB> getObservablePCBList(){
        return PCB_AREA;
    }

    public static PCB getPCB(int PID){
        for(PCB pcb:PCB_AREA){
            if(pcb.getPID()==PID){
                return pcb;
            }
        }
        return null;
    }

    public static synchronized boolean addPCB(PCB pcb){
        try {
            if(PCB_AREA.size()>=10){
                log.warning("进程控制块数量已到达10个的上限");
                return false;
            }
            return PCB_AREA.add(pcb);
        }catch (Exception e){
            e.printStackTrace();

        }
        return false;

    }

    public static boolean removePCB(PCB pcb){
        return PCB_AREA.remove(pcb);
    }


}
